import { CoolController, BaseController, TagTypes, CoolUrlTag } from '@cool-midway/core';
import { UserAnalysisEntity } from '../../entity/analysis';
import { UserAnalysisService } from '../../service/analysis';
import { ALL, Body, Get, Inject, Post, Query } from '@midwayjs/core';

/**
 * 用户-数据分析
 */
@CoolUrlTag({
  key: TagTypes.IGNORE_TOKEN,
  value: ['getYesterdayOverview', 'getDayAnalysisData', 'page'],
})
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: UserAnalysisEntity,
  service: UserAnalysisService,
  pageQueryOp: {
    fieldEq: ['metric', 'name'],
  },
})
export class AdminAnalysisController extends BaseController {
  @Inject()
  UserAnalysisService: UserAnalysisService;
  // 用的微信小程序的数据统计,所以请求的数据都是小于等于昨天的

  /**
   * 获取小游戏广告汇总数据
   */
  @Post('/getAdposGeneral', { summary: '获取小游戏广告汇总数据' })
  public async getAdposGeneral(@Body(ALL) params: any) {
    return this.ok(await this.UserAnalysisService.getAdposGeneral(params));
  }

  /**
 * 获取小游戏广告汇总数据
 */
  @Get('/getDayAnalysisData', { summary: '获取小游戏广告汇总数据' })
  public async getDayAnalysisData(@Query('granularity') granularity: number,@Query('time') time: string) {
    return this.ok(await this.UserAnalysisService.getDayAnalysisData(granularity,time));
  }

  /**
   * 昨日概况
   */
  @Get('/getYesterdayOverview', { summary: '昨日概况' })
  public async getYesterdayOverview() {
    return this.ok(await this.UserAnalysisService.getYesterdayOverview());
  }

  /**
   * 总用户数
   */
  @Get('/getTotalUsers', { summary: '总用户数' })
  public async getTotalUsers() {
    return this.ok(await this.UserAnalysisService.getTotalUsers());
  }

  /**
   * 总访问量
   */
  @Get('/getTotalVisits', { summary: '总访问量' })
  public async getTotalVisits() {
    return this.ok(await this.UserAnalysisService.getTotalVisits());
  }

  /**
  * ecahrt数据
  */
  @Get('/getActiveTrends', { summary: 'ecahrt数据' })
  public async getActiveTrends(@Query('metric') metric: string) {
    return this.ok(await this.UserAnalysisService.getActiveTrends(metric));
  }
}
